// Decompiled by DJ v3.10.10.93 Copyright 2007 Atanas Neshkov  Date: 27/11/2008 22:57:35
// Home Page: http://members.fortunecity.com/neshkov/dj.html  http://www.neshkov.com/dj.html - Check often for new version!
// Decompiler options: packimports(3) 
// Source File Name:   HumanAlgorithm.java

package reversi;

import java.awt.Point;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.Vector;

// Referenced classes of package reversi:
//            Move, ReversiAlgorithm, GameGrid, GameState, 
//            GameController

public class HumanAlgorithm extends MouseAdapter
    implements ReversiAlgorithm
{

    public HumanAlgorithm(GameGrid gamegrid)
    {
        myIndex = 0;
        running = false;
        grid = gamegrid;
        gamegrid.addMouseListener(this);
    }

    public void mouseClicked(MouseEvent mouseevent)
    {
        grid.getClass();
        int i = mouseevent.getPoint().x / 54;
        grid.getClass();
        int j = mouseevent.getPoint().y / 54;
        if(!running || controller == null || state == null || i < 0 || i >= state.getWidth() || j < 0 || j >= state.getHeight() || !state.isPossibleMove(i, j, myIndex))
        {
            return;
        } else
        {
            controller.doMove(new Move(i, j, myIndex));
            return;
        }
    }

    public void requestMove(GameController gamecontroller)
    {
        running = false;
    }

    public void init(GameController gamecontroller, GameState gamestate, int i, int j)
    {
        controller = gamecontroller;
        state = gamestate;
        myIndex = i;
        if(gamestate.getPossibleMoves(myIndex).size() == 0)
            controller.doMove(null);
    }

    public String getName()
    {
        return "Humaani";
    }

    public void run()
    {
        for(running = true; running;)
            try
            {
                Thread.sleep(10L);
            }
            catch(InterruptedException interruptedexception)
            {
                running = false;
            }

    }

    public void cleanup()
    {
        grid.removeMouseListener(this);
    }

    GameGrid grid;
    GameController controller;
    GameState state;
    int myIndex;
    boolean running;
}